// pages/me/me.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isDisabled: wx.getStorageSync("isDisable")
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserInfo();
  },

  // 通过微信获取个人信息
  getUserInfo(cb) {
    var that = this;
    wx.login({
      success: function (res) {
        // console.log(res, "success")

        wx.getUserInfo({
          success: function (res) {
            // console.log(res, "getUserInfo-success")
            that.setData({
              userInfo: res.userInfo,
              isDisabled: true
            });

            wx.setStorageSync("isDisable", that.data.isDisabled)
          },
          fail: function (res) {
            console.log(res, "getUserInfo-fail")
          },
        })
      },

    })
  },


  // 热门
  hotClick: function () {
    this.showToast();
  },

  /**
   * 我的收藏
   */
  likeClick: function () {
    this.showToast();
  },

  /**
  * 关于我们
  */
  // aboutUsClick: function () {
  //   wx.navigateTo({
  //     url: '/pages/aboutus/aboutus',
  //     success: function (res) { },
  //     fail: function (res) { },
  //     complete: function (res) { },
  //   })
  // },

  showToast: function () {
    wx.showToast({
      title: '正在开发中',
      icon: "loading",
      duration: 1500
    })
  },

  // 获取用户信息
  againGetUser(res) {
    var that = this;
    console.log("again", res);
    var text = res.detail.errMsg//getUserInfo:fail auth deny或者getUserInfo:ok

    if (!this.data.isDisabled) {
      if (text === "getUserInfo:ok") {
        console.log("ok");

        that.setData({
          userInfo: res.detail.userInfo,
          isDisabled: true
        });

        wx.setStorageSync("isDisable", that.data.isDisabled)
      }
    }

    // wx.getUserInfo({
    //   success: function (res) {
    //     console.log(res, "getUserInfo-success")
    //     that.setData({
    //       userInfo: res.userInfo
    //     });
    //   },
    // })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})